﻿using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_edition : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string usr = (string)Session["usr"];
        if (usr == null)
        {
            Response.Write("<script>alert('请返回到登录界面登录！!');window.open('login.aspx','_parent')</script>");
            Session.Clear();
        }
        else
        {

            if (!IsPostBack)
            {
                int m = int.Parse(Request.QueryString["id"]);
                string strConnection = "Provider=Microsoft.Jet.OleDb.4.0 ;Data Source=|DataDirectory|\\web.mdb";
                OleDbConnection objConnection = new OleDbConnection(strConnection);
                objConnection.Open();
                string sql = "select * from news where ID=" + m;
                OleDbCommand cmd = new OleDbCommand(sql, objConnection);
                OleDbDataReader reader = cmd.ExecuteReader();
                if (reader.Read())//从数据库读取用户信息
                {
                    string q, w, r, t, y, u, l, k;
                    q = reader["timu"].ToString();
                    w = reader["time1"].ToString();
                    r = reader["bumen"].ToString();
                    t = reader["cishu"].ToString();
                    y = reader["lanmu"].ToString();
                    l = reader["name1"].ToString();
                    k = reader["shenhe"].ToString();
                    u = reader["zw"].ToString();
                    TextBox1.Text = q.Trim(); TextBox2.Text = w.Trim();
                    DropDownList3.SelectedItem.Text = r.Trim();
                    TextBox4.Text = t.Trim();
                    DropDownList2.SelectedItem.Text = y.Trim();
                    TextBox6.Text = l.Trim();
                    DropDownList1.SelectedItem.Text = k.Trim();
                    content.Text = u.Trim();
                }
                reader.Close();
                objConnection.Close();
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int m = int.Parse(Request.QueryString["ID"]);
        string strConnection = "Provider=Microsoft.Jet.OleDb.4.0 ;Data Source=|DataDirectory|\\web.mdb";
        OleDbConnection objConnection = new OleDbConnection(strConnection);
        objConnection.Open();
        string sqlStr = "update news set shenhe='" + DropDownList1.SelectedItem.Text.Trim() + "',timu='"+TextBox1.Text.Trim()+"',time1='"+TextBox2.Text.Trim()+"',bumen='"+DropDownList3.SelectedItem.Text.Trim()+"',lanmu='"+DropDownList2.SelectedItem.Text.Trim()+"',name1='"+TextBox6.Text.Trim()+"',zw='"+content.Text.Trim()+"' where ID=" + m;
        OleDbCommand myCmd = new OleDbCommand(sqlStr, objConnection);
        myCmd.ExecuteNonQuery();
        objConnection.Close();
        Response.Write("<script>alert('修改成功!')</script>");
    }
   

   
}